package com.cp.admin.modular.system.controller;

import com.cp.core.base.controller.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.beans.factory.annotation.Autowired;
import com.cp.admin.core.log.LogObjectHolder;
import org.springframework.web.bind.annotation.RequestParam;
import com.cp.admin.modular.system.model.EthKey;
import com.cp.admin.modular.system.service.IEthKeyService;

/**
 * 系统账户控制器
 *
 * @author fengshuonan
 * @Date 2020-05-05 12:16:57
 */
@Controller
@RequestMapping("/ethKey")
public class EthKeyController extends BaseController {

    private String PREFIX = "/system/ethKey/";

    @Autowired
    private IEthKeyService ethKeyService;

    /**
     * 跳转到系统账户首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "ethKey.html";
    }

    /**
     * 跳转到添加系统账户
     */
    @RequestMapping("/ethKey_add")
    public String ethKeyAdd() {
        return PREFIX + "ethKey_add.html";
    }

    /**
     * 跳转到修改系统账户
     */
    @RequestMapping("/ethKey_update/{ethKeyId}")
    public String ethKeyUpdate(@PathVariable Long ethKeyId, Model model) {
        EthKey ethKey = ethKeyService.selectById(ethKeyId);
        model.addAttribute("item",ethKey);
        LogObjectHolder.me().set(ethKey);
        return PREFIX + "ethKey_edit.html";
    }

    /**
     * 获取系统账户列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
        return ethKeyService.selectList(null);
    }

    /**
     * 新增系统账户
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(EthKey ethKey) {
        ethKeyService.insert(ethKey);
        return SUCCESS_TIP;
    }

    /**
     * 删除系统账户
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Long ethKeyId) {
        ethKeyService.deleteById(ethKeyId);
        return SUCCESS_TIP;
    }

    /**
     * 修改系统账户
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(EthKey ethKey) {
        ethKeyService.updateById(ethKey);
        return SUCCESS_TIP;
    }

    /**
     * 系统账户详情
     */
    @RequestMapping(value = "/detail/{ethKeyId}")
    @ResponseBody
    public Object detail(@PathVariable("ethKeyId") Long ethKeyId) {
        return ethKeyService.selectById(ethKeyId);
    }
}
